package com.hui.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

@Configuration
@EnableSwagger2
public class Swagger2 {
    //swagger2 核心配置  docket   localhost:8088/swagger-ui.html
    @Bean
    public Docket createRestApi(){
        return new Docket(DocumentationType.SWAGGER_2) ////指定api类型为swagger2
                .apiInfo(apiInfo())          //用于api文档汇总
                .select()
                .apis(RequestHandlerSelectors
                        .basePackage("com.hui.controller")) //指定Controller
                .paths(PathSelectors.any())
                .build();
    }

    private ApiInfo apiInfo(){
        return new ApiInfoBuilder()
                .title("单体电商API")     //文档标题
                .contact(new Contact("ahui",
                        "www.ahui.com",
                        "maxhui@com"))  //联系人
                .description("特别API文档")     //详细信息
                .version("1.0.0")   //文档版本号
                .termsOfServiceUrl("www.ahui.com")  //网站地址
                .build();   //构建文档
    }
}
